package org.zlb.algorithm.sort;

/**
 * 选择排序
 *
 * @author zhoulingbo
 * @date 2021/7/8 10:37
 */
public class SelectionSort extends AbstractSort{

    public void sort(int[] arr) {
        for (int i=0; i<arr.length-1; i++) {
            int maxIndex = 0;
            for (int j=1; j<arr.length-1-i; j++) {
                if (compare(arr[j], arr[maxIndex]) > 0) {
                    maxIndex = j;
                }
            }
            if (maxIndex != arr.length-i-1) {
                swap(arr, maxIndex, arr.length-i-1);
            }
        }
    }

}
